package com.example.smartcity.Mappers;

import com.example.smartcity.Entity.News;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface NewsMapper {
    @Select("SELECT * FROM news WHERE title LIKE  CONCAT('%', #{words}, '%') OR content LIKE CONCAT('%', #{words2}, '%');")
     List<News> findByTitleOrContent(@Param("words") String words,@Param("words2")String words2);
    @Select("SELECT * FROM news WHERE id = #{id};")
     News getNewsById(@Param("id") int id);
    @Select("UPDATE news SET views_number = (SELECT views_number FROM news WHERE id = #{id})+1 WHERE id = #{id};")
     void updateViewsNumber(int id);
    @Select("UPDATE news SET likes_number = (SELECT likes_number FROM news WHERE id = #{id})+1 WHERE id = #{id};")
    void updateLikesNumber(int id);
    @Select("SELECT * from news WHERE press_category = #{category}")
    List<News> findNewsByCategory(@Param("category") String category);

    @Select("SELECT * FROM news ORDER BY id desc")
    List<News> findAll();

}
